package net.kem.android.positioner;

import java.util.Locale;

import android.os.Parcel;
import android.os.Parcelable;

public class MessageObject implements Parcelable {
	private static final String TEMPLATE_OBJECT =
		"<object>" +
			"<idObject>%d</idObject>" +
			"<idCategory>%d</idCategory>" +
			"<idObjectType>%d</idObjectType>" +
			"<name>%s</name>" +
			"<state>%s</state>" +
		"</object>";//dddss

	private int id;
	private int category;
	private int type;
	private String name;
	private String state;

	public MessageObject() {}

	/**
	 * This constructor for internal tests.
	 * @param id
	 * @param type
	 * @param name
	 * @param state
	 */
	public MessageObject(int id, int category, int type, String name, String state) {
		super();
		this.id = id;
		this.category = category;
		this.type = type;
		this.name = name;
		this.state = state;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getCategory() {
		return category;
	}

	public void setCategory(int category) {
		this.category = category;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String toString() {
		return new StringBuilder(64).append('[').append(id).append("] (")
				.append(category).append(", ")
				.append(type).append(")\t")
				.append(name).append(": ")
				.append(state).toString();
	}

	public String toXML() {
		String res = String.format(Locale.ENGLISH, TEMPLATE_OBJECT, id, category, type, name, state);
		return res;
	}

	// Parcel part
	public MessageObject(Parcel in) {
		id = in.readInt();
		category = in.readInt();
		type = in.readInt();
		name = in.readString();
		state = in.readString();
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(id);
		dest.writeInt(category);
		dest.writeInt(type);
		dest.writeString(name);
		dest.writeString(state);
	}

	public static final Parcelable.Creator<MessageObject> CREATOR = new Parcelable.Creator<MessageObject>() {
		@Override
		public MessageObject createFromParcel(Parcel source) {
			return new MessageObject(source); // using parcelable constructor
		}

		@Override
		public MessageObject[] newArray(int size) {
			return new MessageObject[size];
		}
	};
}